package com.frx.datastruct.chapterthree;

import com.frx.datastruct.chapterfour.LinkedListQueue;

import java.util.Random;

/**
 * Created by xurenfeng on 2019/2/16.
 *  比较循环队列与数组队列
 */
public class Main {
    private static double testQueue(Queue<Integer> q, int opCount){

        long startTime = System.nanoTime();
        Random random = new Random();
        for (int i = 0; i < opCount; i++){
            q.enqueue(random.nextInt(Integer.MAX_VALUE));
        }
        for (int i = 0; i < opCount;i++){
            q.dequeue();
        }
        long endTime = System.nanoTime();
        return  (endTime - startTime)/1000000000.0;
    }

    public static void main(String[] args){

        int opCount = 100000;
        ArrayQueue<Integer> arrayQueue = new ArrayQueue<>();
        double time1 = testQueue(arrayQueue,opCount);
        System.out.println("数组队列消耗的时间为：" + time1  + "s");
        LoopQueue<Integer> loopQueue = new LoopQueue<>();
        double time2 = testQueue(loopQueue,opCount);
        System.out.println("循环队列消耗的时间为：" + time2 + "s");

        LinkedListQueue<Integer> listQueue = new LinkedListQueue<>();

        double time3 = testQueue(listQueue,opCount);
        System.out.println("链表实现的队列消耗的时间为：" + time3 + "s");
    }


}
